package com.haq.housesystem.ctrl;

import com.github.pagehelper.PageInfo;
import com.haq.housesystem.bean.Admins;
import com.haq.housesystem.bean.HousesOrient;
import com.haq.housesystem.bean.HousesType;
import com.haq.housesystem.service.HousesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/housesType")
public class HousesTypeCtrl {
    @Autowired
    HousesTypeService housesTypeService;

    @RequestMapping("/insert")
    public Map insert(HousesType housesType){
        housesTypeService.insert(housesType);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("/update")
    public Map update(HousesType housesType){
        housesTypeService.update(housesType);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("/delete")
    public Map delete(int typeId){
        housesTypeService.delete(typeId);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("deleteByIds")
    public Map deleteByIds(int [] typeIds){
        housesTypeService.deleteByIds(typeIds);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("selectAll")
    public Map selectAll(){

        List<HousesType> housesTypeList=housesTypeService.selectAll();
        Map map=new HashMap();
        map.put("state","success");
        map.put("housestypelist",housesTypeList);
        return map;
    }
    @RequestMapping("selectByName")
    public Map selectByName(String typeName){

        List<HousesType> housesTypeList=housesTypeService.selectByName(typeName);
        Map map=new HashMap();
        map.put("state","success");
        map.put("housestypelist",housesTypeList);
        return map;
    }
    @RequestMapping("selectById")
    public Map selectById(int typeId){

        HousesType housesType=housesTypeService.selectById(typeId);
        Map map=new HashMap();
        map.put("state","success");
        map.put("housestypelist",housesType);
        return map;
    }
    //分页查询全部
    @RequestMapping("/selectAllByPageInfo")
    public Map selectAllByPageInfo(@RequestParam(required=false,defaultValue="1")int curPage, @RequestParam(required=false,defaultValue="3")int size) {
        PageInfo<HousesType> pageInfo = housesTypeService.selectAllByPageInfo(curPage, size);

        Map map=new HashMap();
        map.put("state", "success");
        //list数据
        map.put("housestypelist", pageInfo.getList());
        //总记录数
        map.put("total", pageInfo.getTotal());
        return map;
    }
    @RequestMapping("/selectByNameByPageInfo")
    public Map selectAllByIdByNameStatePageInfo(@RequestParam(required=false,defaultValue="1")int curPage,@RequestParam(required=false,defaultValue="3")int size,String typeName) {
        PageInfo<HousesType> pageInfo = housesTypeService.selectByNameByPageInfo(curPage, size, typeName);

        Map map=new HashMap();
        map.put("state", "success");
        //list数据
        map.put("housestypelist", pageInfo.getList());
        //总记录数
        map.put("total", pageInfo.getTotal());
        return map;
    }
}
